fix(firewall): avoid parsing flags from chain names and quoted values#1275
Open
ashishrase wants to merge 2 commits intopuppetlabs:mainfrom
Open
fix(firewall): avoid parsing flags from chain names and quoted values#1275ashishrase wants to merge 2 commits intopuppetlabs:mainfrom
ashishrase wants to merge 2 commits intopuppetlabs:mainfrom
Conversation
3b535d0 to
3492bb8
Compare
55b1ed8 to
726bef0
Compare
Author
|
Need few more test to be done |
Author
|
What’s in this change: |
Make rule discovery in firewall.rb treat iptables options as real tokens instead of matching flag-like substrings anywhere in the rule text. This fixes cases where rule_to_hash could misread `-p` from chain names ending in `-p` or from quoted payloads, producing malformed values such as `proto => '-p'` and later failing with: Unsupported proto number: -p The change keeps existing fw_ naming intact, updates rule parsing to use token boundaries, preserves quoted-value parsing for attributes that are meant to read quoted payloads, and adds provider specs for both unit and end-to-end discovery.
19fec76 to
b8de7fd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix firewall rule discovery so flag-like substrings inside chain names and quoted values are not parsed as real iptables options.
Today
rule_to_hashinlib/puppet/provider/firewall/firewall.rbparses most attributes by scanning the full rawiptables-saveline with regexes. That allows matches to happen in places that are not real option tokens, for example:-p-AOn affected systems this can cause the parser to manufacture malformed values such as
proto => '-p'. Once that happens,process_getreceives an invalid proto value and discovery can later fail with:Unsupported proto number: -pThis change fixes the parser at the source by:
-p tcpproto => allfallback when no real protocol is presentIt does not change
utility.rband does not changefirewallchain.rb.Additional Context
Root cause / reproduction
On affected systems,
iptables-saveoutput can contain rules where the raw line includes flag-like substrings that are not real option tokens, for example:-p, followed by a real-p udp-A-p -por! -p -pBecause
rule_to_hashscans the full raw rule line, those substrings can be mistaken for real options. In the failing case, the parser can storeproto => '-p', and later in discovery this surfaces as:Unsupported proto number: -pThis can cause
Puppet::Type.type(:firewall).instancesto fail during rule discovery and can also breakfirewallchainresource generation that depends on discovered firewall state.Thought process behind the implementation
The goal of this change is to fix the root cause in the provider parser rather than make downstream protocol conversion more tolerant of malformed intermediate values.
process_getalready handles a missing protocol by defaulting toall, so the correct fix is to stoprule_to_hashfrom manufacturing invalid protocol values in the first place.Using token-boundary-aware matching ensures that flags such as
-pand-Aare only parsed when they appear as real iptables option tokens, not when they appear inside chain names or other arbitrary substrings. Quoted payload masking is still kept for the non-quoted parsing branches so quoted content is not interpreted as flags.Test Coverage
Also adds provider test coverage for:
-p -pdo not setproto! -p -pdo not setprotoproto-p tcpoutside quotes still parses asproto => tcp-pdo not causeproto => '-p'-Ado not confuse chain parsinggetreturnsproto => allwhen no real protocol is presentgetdoes not surface-p/! -pas protocol values-pstill parse the real protocol correctlyRelated Issues (if any)
No linked issue yet.
Checklist
Acceptance tests were not run locally because Docker/Litmus provisioning is not available in my environment.
puppet agent -ton an affected system)